home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / util / moni / ramspeed.lha / ramspeed.c < prev    next >
C/C++ Source or Header  |  1993-10-15  |  4KB  |  190 lines

  1. /*
  2. **    $VER: ramspeed  Release (15.12.93)
  3. **
  4. **    Ram Test , tests bulk memeory copies using cpu with display dma acting
  5. **               as a test of slow down
  6. **
  7. **  Programmed by : Raul A. Sobon.
  8. **
  9. **    (C) Copyright 1993 \.../ TM, Inc.
  10. **        All Rights Reserved
  11. */
  12.  
  13.  
  14. #include <exec/types.h>
  15. #include <exec/memory.h>
  16. #include <exec/execbase.h>
  17.  
  18. #include <dos/dos.h>
  19. #include <dos/dosextens.h>
  20. #include <dos/stdio.h>                // dos stdio
  21.  
  22. #include <graphics/gfxbase.h>
  23. #include <exec/memory.h>
  24. #include <intuition/classes.h>
  25. #include <intuition/gadgetclass.h>
  26. #include <intuition/intuitionbase.h>
  27.  
  28. #include <proto/exec.h>                // use amiga library stuff
  29. #include <proto/dos.h>
  30. #include <proto/graphics.h>
  31. #include <proto/intuition.h>
  32.  
  33. #include <stdio.h>                    // and the thing we all use!
  34. #include <stdlib.h>
  35. #include <string.h>
  36. #include <time.h>
  37. #include <dos.h>
  38.  
  39.  
  40. extern    void bulkcopy( APTR source, APTR dest, LONG size);
  41.  
  42.  
  43.  
  44.  
  45. APTR            MainVisualInfo;
  46. struct Screen    *MainScreen;
  47. #include    "ramspeed_rev.h"
  48. static    UBYTE    verstr[]={ VERSTAG };
  49.  
  50.  
  51.  
  52.  
  53.  
  54. /*
  55.  * --- Open lots of libraries that I need.
  56.  */
  57. long OpenLibraries( void ){
  58.  
  59.     if ( !(GfxBase = (struct GfxBase *) OpenLibrary((UBYTE *) "graphics.library" , 33l ))) {
  60.         WriteStr("\graphics.library\n");
  61.         return FALSE;
  62.         }
  63.  
  64.     if ( !(DOSBase = (struct DosLibrary *) OpenLibrary((UBYTE *) "dos.library", 33l ))) {
  65.         WriteStr("\tdos.library\n");
  66.         return FALSE;
  67.         }
  68.  
  69.     if ( !(IntuitionBase = (struct IntuitionBase *) OpenLibrary((UBYTE *) "intuition.library", 33l ))) {
  70.         WriteStr("\tintuition.library\n");
  71.         return FALSE;
  72.         }
  73.  
  74.     return TRUE;
  75. }
  76.  
  77.  
  78.  
  79.  
  80. /*
  81.  * --- Close the libraries which are opened by me.
  82.  */
  83. void CloseLibraries( void ){
  84.     if (IntuitionBase)    CloseLibrary( (struct Library *) IntuitionBase );
  85.     if (DOSBase)        CloseLibrary( (struct Library *) DOSBase );
  86.     if (GfxBase)        CloseLibrary( (struct Library *) GfxBase );
  87. }
  88.  
  89.  
  90.  
  91.  
  92.  
  93. void ShowArgs( void ){
  94.     puts("RamSpeed (c) Raul A. Sobon,  Dec-1993");
  95.     puts("options are :");
  96.     puts("    CHIP2FAST ... copy chip ram to fast ram");
  97.     puts("    FAST2FAST ... copy fast ram to fast ram");
  98.     puts("    CHIP2CHIP ... copy chip ram to chip ram");
  99.     puts("    FAST2CHIP ... copy fast ram to chip ram");
  100. }
  101.  
  102.  
  103.  
  104. #define    MOVESIZE    10000000
  105. #define    BLOCKSIZE    0xf000
  106.  
  107.  
  108.     APTR    source;
  109.     APTR    dest;
  110.  
  111.  
  112.  
  113.  
  114. ULONG    GetSysTime( void ){
  115.     unsigned int t1[2]={0,0};
  116.  
  117.     timer( t1 );
  118. //    printf("t1=%ld t2=%ld\n",t1[0],t1[1]);
  119.  
  120.     return ( (1000*t1[0])+(t1[1]/1000) );
  121.  
  122. }
  123.  
  124. void TestRam( void ){
  125.     ULONG    time1,time2,time3,blksize,bpms,nsb,lp;
  126.  
  127.     printf("Moving %ld BYTES ...\n", MOVESIZE );
  128.     blksize = (BLOCKSIZE>>2)-1;
  129.     time1=GetSysTime();
  130.     Forbid();
  131.     for(lp=0;lp<(MOVESIZE/BLOCKSIZE);lp++){
  132.         bulkcopy( source, dest, blksize );
  133.     }
  134.     Permit();
  135.  
  136.     time2 = GetSysTime();
  137.     time3 = time2-time1;
  138.     if( time3 == 0 ) {printf("error\n"); return; };
  139.     bpms = MOVESIZE/time3;
  140.     nsb = 1000000/bpms;
  141.  
  142.     puts("done.");
  143.  
  144.     printf("It took %ld ms to move %ld bytes of data\n",time3,MOVESIZE);
  145.     printf("Which is %ld bytes/sec\n", bpms*1000 );
  146.     printf("Which is %ld ns/byte\n", nsb );
  147.     printf("Which is %ld color clock cycles/byte\n", (nsb/280)+1 );
  148.     printf("Which is %ld 12Mhz 68020 cycles/byte\n", (nsb/83)+1 );
  149.     printf("Which is %ld 25Mhz 68040 cycles/byte\n", (nsb/42)+1 );
  150. }
  151.  
  152.  
  153. // ----------------------------------------------------------------------------------------------
  154. int main( int argc,char *argv[] ) {
  155.     BOOL                 running  = TRUE;
  156.     APTR    fastram,chipram;
  157.  
  158.     OpenLibraries();
  159.  
  160.     fastram = AllocVec( BLOCKSIZE, MEMF_PUBLIC );
  161.     chipram = AllocVec( BLOCKSIZE, MEMF_CHIP );
  162.  
  163.  
  164.     if( argc < 2 )
  165.         ShowArgs();
  166.     else
  167.     if( !strncmp( "CHIP2FAST",argv[1],9) || !strncmp( "chip2fast",argv[1],9) ) {
  168.         source = chipram; dest = fastram;  TestRam();    }
  169.     else
  170.     if( !strncmp( "FAST2FAST",argv[1],9) || !strncmp( "fast2fast",argv[1],9) ) {
  171.         source = fastram; dest = fastram;  TestRam();    }
  172.     else
  173.     if( !strncmp( "CHIP2CHIP",argv[1],9) || !strncmp( "chip2chip",argv[1],9) ) {
  174.         source = chipram; dest = chipram;  TestRam();    }
  175.     else
  176.     if( !strncmp( "FAST2CHIP",argv[1],9) || !strncmp( "fast2chip",argv[1],9) ) {
  177.         source = fastram; dest = chipram;  TestRam();    }
  178.     else
  179.         ShowArgs();
  180.  
  181.  
  182.     FreeVec( fastram );
  183.     FreeVec( chipram );
  184.  
  185.     CloseLibraries();
  186.  
  187.     Exit( TRUE );
  188. }
  189.  
  190.